package servlet;

import entity.Battery;
import service.BatteryService;
import service.impl.BatteryServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet(urlPatterns = "/BatteryUpdateServlet")
public class BatteryUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setContentType("text/html;charset=utf-8");
        int id = Integer.parseInt(request.getParameter("id"));
        String carName = request.getParameter("carName");
        String cityName = request.getParameter("cityName");
        String userName = request.getParameter("userName");
        int pressureValue= Integer.parseInt(request.getParameter("pressureValue"));
        String time = request.getParameter("time");

        Battery battery = new Battery();
        battery.setPressureValue(pressureValue);
        battery.setUserName(userName);
        battery.setCityName(cityName);
        battery.setCarName(carName);
        battery.setTime(time);
        battery.setId(id);
        BatteryService batteryService = new BatteryServiceImpl();
        int j  = batteryService.update(battery);
        if (j>0){
            request.getRequestDispatcher("powerbattery/powerbattery_All.jsp").forward(request,response);
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
